package dch.struts2.page.action;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import dch.entity.Acomment;
import dch.entity.Page;
import dch.service.page.dao.AcommentService;
import dch.service.page.impl.AcommentServiceImpl;

@Namespace("/comment")
@Results({
	@Result(name="comment",location="/comment.jsp")
})
public class CommentAction  extends ActionSupport {
	
	private static final long serialVersionUID = 1L;
	private AcommentService acService=null;
	private Acomment ac=null;
	private int currentPage=1;
	private Page page=null;
	private int id=0;
	private dch.entity.Result comments=null;
	public CommentAction(){
		acService=new AcommentServiceImpl();
	}
	
	@Action("/addComment")
	public void insert(){
		HttpServletRequest request=ServletActionContext.getRequest();
		String ip=request.getRemoteAddr();
		try{
			ac.setUserip(ip);
			ac.getAlbum().setAlbumid(id);
			acService.insert(ac);
			acService.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	@Action("/commentList")
	public String commentList(){
		page=new Page(currentPage);
		comments=acService.queryByPage(page,id);
		return "comment";
	}
	
	public Acomment getAc() {
		return ac;
	}
	public void setAc(Acomment ac) {
		this.ac = ac;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public dch.entity.Result getComments() {
		return comments;
	}

	public void setComments(dch.entity.Result comments) {
		this.comments = comments;
	}
	
}
